package ${package}.${serviceImpl};

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
import ${package}.common.Result;
import ${package}.${entity}.${simpleName};
import ${package}.${mapper}.${simpleName}Mapper;
import ${package}.${service}.${simpleName}Service;

@Service
@Slf4j
public class ${simpleName}ServiceImpl implements ${simpleName}Service {

    @Autowired
    private ${simpleName}Mapper ${paramName}Mapper;

    @Override
    public Result<IPage<${simpleName}>> listPage(Integer pageNo, Integer pageSize) {

        Page<${simpleName}> page = new Page<>(pageNo, pageSize);
        List<${simpleName}> list = ${paramName}Mapper.listPage(page, 1);
        page.setRecords(list);
        return Result.ok(page);
    }

    @Override
    public Result<IPage<${simpleName}>> selectPage(Integer pageNo, Integer pageSize) {

        Page<${simpleName}> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<${simpleName}> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.orderByDesc(${simpleName}::getId);

        IPage<${simpleName}> list = ${paramName}Mapper.selectPage(page, queryWrapper);
        return Result.ok(list);
    }

    @Override
    public Result<${simpleName}> getById(Serializable id) {
        ${simpleName} ${paramName} = ${paramName}Mapper.selectById(id);
        return Result.ok(${paramName});
    }

    @Override
    public Result add(${simpleName} ${paramName}) {
        ${paramName}Mapper.insert(${paramName});
        return Result.ok();
    }

    @Override
    public Result updateById(${simpleName} ${paramName}) {
        ${paramName}Mapper.updateById(${paramName});
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        for (Integer id : ids) {
            ${paramName}Mapper.deleteById(id);
        }
        return Result.ok();
    }
}